<template>
  <div class="companysTable">
    <!-- 表格 -->
    <el-table :data="tableData" style="width: 100%;margin-top:30px">
      <el-table-column type="index" label="序号" width="80" align="center"> </el-table-column>
      <el-table-column prop="number" label="企业编号" align="center"> </el-table-column>
      <el-table-column prop="shortName" label="企业简称" align="center"> </el-table-column>
      <el-table-column prop="tags" label="标签" align="center"> </el-table-column>
      <el-table-column prop="creatorID" label="创建者" align="center"> </el-table-column>
      <el-table-column prop="addDate" label="创建日期" align="center"> </el-table-column>
      <el-table-column prop="remarks" label="备注" align="center"> </el-table-column>
      <el-table-column prop="state" label="状态" align="center">
        <template v-slot="{ row }">
          <span v-if="row.state">启用</span>
          <span v-else>禁用</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200px">
        <template v-slot="{ row }">
          <el-button type="primary" icon="el-icon-edit" plain circle @click="editClick(row)" />
          <el-button v-if="row.state" type="warning" icon="el-icon-close" plain circle @click="disableClick(row)" />
          <el-button v-else type="success" icon="el-icon-check" plain circle @click="disableClick(row)" />
          <el-button type="danger" icon="el-icon-delete" plain circle @click="delClick(row.id)" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { delCompanys } from '../../../api/companys';
export default {
  name: '',
  components: {},
  props: {
    tableData: {
      type: Array,
      default: null
    }
  },
  data() {
    return {};
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // 删除
    delClick(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          await delCompanys(id);
          this.$emit('delCompanys');

          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    // 编辑
    editClick(row) {
      this.$emit('editClick', row);
    },
    // 启用禁用
    disableClick(row) {
      this.$confirm('此操作将永久修改此状态吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          this.$emit('disableClick', row);

          this.$message({
            type: 'success',
            message: '修改成功!'
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
    }
  }
};
</script>
<style lang="less" scoped></style>
